<?=$header?>

<script src="<?=base_url();?>system/scriptaculous/lib/prototype.js" type="text/javascript"></script>
<script src="<?=base_url();?>system/scriptaculous/src/scriptaculous.js" type="text/javascript"></script>
<script src="<?=base_url();?>system/scriptaculous/src/unittest.js" type="text/javascript"></script>

<script language="javascript" type="text/javascript">
function deleteNews(id){
	if(confirm('Are you sure you want to delete this news?')){
		window.location="<?=base_url();?>news/delete/"+id;
	} 
}
</script>

<p>Add the <a href="#" onclick="Effect.toggle('news_add','slide'); return false;">latest news</a> or select an article to edit:
<div id="news_add" style="display:none;">
<?
echo form_open('news/create');
echo form_input('heading', 'Write the title here...'); 
echo '<br />';
echo '<textarea name="content" cols="60" rows="5" >Write your news here...</textarea>';
echo '<br />';
echo form_submit('submit', 'Add News'); 
echo form_close();
?>
<br />
</div>


<? 
function mysql_to_date($date){
	//Y-m-d H:i:s
	$temp = split(' ', $date);
	$date = $temp[0];
	$time = $temp[1];
	$temp2 = explode('-', $date);
	$temp3 = explode(':', $time);
	
	//Date
	$year = $temp2[0];
	$month = $temp2[1];
	$day = $temp2[2];
	//Time
	$hour = $temp3[0];
	$minute = $temp3[1];
	$second = $temp3[2];
	return "($day/$month/$year, $hour:$minute)";
}
	
	$this->load->database();
	$query = $this->db->query('SELECT * FROM gcms_news ORDER BY news_date DESC');
	foreach ($query->result() as $row)
	{
		echo '<div class="option_box">';
		echo '<div class="boxmeta">'.mysql_to_date($row->news_date).'</div><a href="news/edit/'.$row->ID.'"><h2>'.$row->news_heading.'</h2></a>';
		echo '<p>';
		if(strlen($row->news_content) > 100){
			echo substr($row->news_content, 0, 100).'...';
		} else {
			echo $row->news_content;
		}
		echo '<br /><div style="float:right;padding-right:8px;">
		<a href="news/edit/'.$row->ID.'" style="border:0;"><img src="'.base_url().'system/images/pencil.png" alt="edit news" border="0" /></a>
		<a href="#" onclick="deleteNews(\''.$row->ID.'\');" style="border:0;"><img src="'.base_url().'system/images/delete.png" alt="delete news" border="0" /></a>
		</div><hr class="cleaner" /></p>';
		echo '</div>';
	}
?>

<?=$footer?>

</body>
</html>